// pages/wdht/wdht.js
var common = require('../../utils/common.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    htlist: [],
    array: [],
    index: 0,
    total: 0,
    page:1,
    houseId:"",
    pullUp:true,//上拉
  },
  //选择房源
  bindPickerChange: function (e) {
    var that = this;
    var index= e.detail.value;
    var id = this.data.array[index].houseId;
    this.setData({
      htlist: [],
      index:index,
      page:1,
      houseId: id,
    })
    console.log('选择房源')
    this.getHouse(id);
   
  },
  getHouse: function (houseId) {
    console.log(houseId + '&&&&' + this.data.page)
    var that = this;
    common._get('/wx/contract/list', {houseId: houseId},
      //成功
      function (res) {
        if (res.data.success) {
          console.log(res.data);
          if (res.data.data){
            var temp = that.data.htlist.concat(res.data.data);
            that.setData({
              htlist: temp
            })
            console.log(111111111);
            console.log(that.data.htlist);
          }
          
        }
      });
  },
  totjht: function () {
    wx.navigateTo({
      url: '../addTenant/addTenant'
    })
  },

  initData:function(){
    var that = this;
    this.getHouse('');
      
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var m = wx.getStorageSync('modifyRoom')
    wx.removeStorageSync('modifyRoom')
    var refresh = app.getRefresh();
    if (m || refresh){
      console.log("生命周期函数--监听页面显示")
      this.data.htlist = [];
      this.data.page = 1;
      this.initData();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading(); //在标题栏中显示加载
    this.setData({
      htlist:[]
    })
    this.initData();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
   
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})